home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib43 / mntlib / strerror.c < prev    next >
C/C++ Source or Header  |  1994-01-15  |  5KB  |  179 lines

  1. /* from Henry Spencer's stringlib */
  2. #include <string.h>
  3.  
  4. static char nullstr[] = "unknown error";
  5.  
  6. char *sys_errlist[] =
  7.     {
  8.     "OK",                    /* 0 */
  9.     "error",                /* 1 */
  10.     "drive not ready",            /* 2 */
  11.     "unknown command",            /* 3 */
  12.     "crc error",                /* 4 */
  13.     "bad request",                /* 5 */
  14.     "seek error",                /* 6 */
  15.     "unknown media",            /* 7 */
  16.     "sector not found",            /* 8 */
  17.     "out of paper",                /* 9 */
  18.     "write failure",            /* 10 */
  19.     "read failure",                /* 11 */
  20.     "general mishap",            /* 12 */
  21.     "media write protected",        /* 13 */
  22.     "media changed",            /* 14 */
  23.     "unknown device",            /* 15 */
  24.     "bad sectors on format",        /* 16 */
  25.     "disk swap request",            /* 17 */
  26.     nullstr,                /* 18 */
  27.     nullstr,                /* 19 */
  28.     nullstr,                /* 20 */
  29.     nullstr,                /* 21 */
  30.     nullstr,                /* 22 */
  31.     nullstr,                /* 23 */
  32.     nullstr,                /* 24 */
  33.     nullstr,                /* 25 */
  34.     nullstr,                /* 26 */
  35.     nullstr,                /* 27 */
  36.     nullstr,                /* 28 */
  37.     nullstr,                /* 29 */
  38.     nullstr,                /* 30 */
  39.     nullstr,                /* 31 */
  40.     "invalid function number",        /* 32 */
  41.     "file not found",            /* 33 */
  42.     "path not found",            /* 34 */
  43.     "no more handles",            /* 35 */
  44.     "access denied",            /* 36 */
  45.     "invalid handle",            /* 37 */
  46.     nullstr,                /* 38 */
  47.     "out of memory",            /* 39 */
  48.     "invalid memory block",            /* 40 */
  49.     nullstr,                /* 41 */
  50.     nullstr,                /* 42 */
  51.     nullstr,                /* 43 */
  52.     nullstr,                /* 44 */
  53.     nullstr,                /* 45 */
  54.     "invalid drive id",            /* 46 */
  55.     nullstr,                /* 47 */
  56.     "rename across drives",            /* 48 */
  57.     "no more files",            /* 49 */
  58.     nullstr,                /* 50 */
  59.     nullstr,                /* 51 */
  60.     nullstr,                /* 52 */
  61.     nullstr,                /* 53 */
  62.     nullstr,                /* 54 */
  63.     nullstr,                /* 55 */
  64.     nullstr,                /* 56 */
  65.     nullstr,                /* 57 */
  66.     nullstr,                /* 58 */
  67.     nullstr,                /* 59 */
  68.     nullstr,                /* 60 */
  69.     nullstr,                /* 61 */
  70.     nullstr,                /* 62 */
  71.     nullstr,                /* 63 */
  72.     "range error/bad argument",        /* 64 */
  73.     "internal error",            /* 65 */
  74.     "bad executable format",        /* 66 */
  75.     "memory block growth failure",        /* 67 */
  76.     nullstr,                /* 68 */
  77.     nullstr,                /* 69 */
  78.     nullstr,                /* 70 */
  79.     nullstr,                /* 71 */
  80.     nullstr,                /* 72 */
  81.     nullstr,                /* 73 */
  82.     nullstr,                /* 74 */
  83.     nullstr,                /* 75 */
  84.     nullstr,                /* 76 */
  85.     nullstr,                /* 77 */
  86.     nullstr,                /* 78 */
  87.     nullstr,                /* 79 */
  88.     "too many symbolic links",        /* 80 */
  89.     "broken pipe",                /* 81 */
  90.     nullstr,                /* 82 */
  91.     nullstr,                /* 83 */
  92.     nullstr,                /* 84 */
  93.     "file already exists",            /* 85 */
  94.     "name too long",            /* 86 */
  95.     "not a tty",                /* 87 */
  96.     "range error",                /* 88 */
  97.     "domain error",                /* 89 */
  98.     "I/O error",                /* 90 */
  99.     "disk full",                /* 91 */
  100.     nullstr,                /* 92 */
  101.     nullstr,                /* 93 */
  102.     nullstr,                /* 94 */
  103.     nullstr,                /* 95 */
  104.     nullstr, nullstr, nullstr, nullstr, nullstr,    /* 96 - 100 */
  105.     nullstr, nullstr, nullstr, nullstr, nullstr,    /* 101 - 105 */
  106.     nullstr, nullstr, nullstr, nullstr, nullstr,    /* 106 - 110 */
  107.     nullstr, nullstr, nullstr, nullstr, nullstr,    /* 111 - 115 */
  108.     nullstr, nullstr, nullstr, nullstr, nullstr,    /* 116 - 120 */
  109.     nullstr, nullstr, nullstr, nullstr, nullstr,    /* 121 - 125 */
  110.     nullstr,                /* 126 */
  111.     nullstr,                /* 127 */
  112.     "interrupted system call"        /* 128 */
  113.     };
  114.  
  115. int    sys_nerr = (int)(sizeof(sys_errlist)/sizeof(sys_errlist[0]));
  116.  
  117. #ifdef __MINT__
  118.  
  119. /* Support for Kay Roemer's socket library */
  120.  
  121. char *const _sock_errlist[] = {
  122.     "Socket operation on non-socket",        /* 300 */
  123.     "Destination address required",
  124.     "Message too long",
  125.     "Protocol wrong type for socket",
  126.     "Protocol not available",
  127.     "Protocol not supported",
  128.     "Socket type not supported",
  129.     "Operation not supported",
  130.     "Protocol family not supported",
  131.     "Address family not supported by protocol",
  132.     "Address already in use",
  133.     "Cannot assign requested address",
  134.     "Network is down",
  135.     "Network is unreachable",
  136.     "Network dropped conn. because of reset",
  137.     "Software caused connection abort",
  138.     "Connection reset by peer",
  139.     "Socket is already connected",
  140.     "Socket is not connected",
  141.     "Cannot send after shutdown",
  142.     "Connection timed out",
  143.     "Connection refused",
  144.     "Host is down",
  145.     "No route to host",
  146.     "Operation already in progress",
  147.     "Operation now in progress",
  148.     "Operation would block"
  149. };
  150.  
  151. int    _sock_nerr = (int)(sizeof (_sock_errlist) / sizeof (char *));
  152.  
  153. #define MINSOCKERR    300
  154. #define MAXSOCKERR    (MINSOCKERR + _sock_nerr)
  155.  
  156. #endif
  157.  
  158. /*
  159.  * strerror - map error number to descriptive string
  160.  *
  161.  */
  162.  
  163. char *
  164. strerror(errnum)
  165. int errnum;
  166. {
  167.     extern int sys_nerr;
  168.     extern char *sys_errlist[];
  169.  
  170.     if (errnum >= 0 && errnum < sys_nerr)
  171.         return(sys_errlist[errnum]);
  172. #ifdef __MINT__
  173.     else if (errnum >= MINSOCKERR && errnum < MAXSOCKERR)
  174.         return(_sock_errlist[errnum - MINSOCKERR]);
  175. #endif
  176.     else
  177.         return(nullstr);
  178. }
  179.